package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SeckillRecord;
import com.ruoyi.system.service.ISeckillRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 秒杀记录Controller
 * 
 * @author kinglu
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/SeckillRecord")
public class SeckillRecordController extends BaseController
{
    @Autowired
    private ISeckillRecordService seckillRecordService;

    /**
     * 查询秒杀记录列表
     */
    @RequiresPermissions("system:SeckillRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(SeckillRecord seckillRecord)
    {
        startPage();
        List<SeckillRecord> list = seckillRecordService.selectSeckillRecordList(seckillRecord);
        return getDataTable(list);
    }

    /**
     * 导出秒杀记录列表
     */
    @RequiresPermissions("system:SeckillRecord:export")
    @Log(title = "秒杀记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SeckillRecord seckillRecord)
    {
        List<SeckillRecord> list = seckillRecordService.selectSeckillRecordList(seckillRecord);
        ExcelUtil<SeckillRecord> util = new ExcelUtil<SeckillRecord>(SeckillRecord.class);
        util.exportExcel(response, list, "秒杀记录数据");
    }

    /**
     * 获取秒杀记录详细信息
     */
    @RequiresPermissions("system:SeckillRecord:query")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(seckillRecordService.selectSeckillRecordByRecordId(recordId));
    }

    /**
     * 新增秒杀记录
     */
    @RequiresPermissions("system:SeckillRecord:add")
    @Log(title = "秒杀记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SeckillRecord seckillRecord)
    {
        return toAjax(seckillRecordService.insertSeckillRecord(seckillRecord));
    }

    /**
     * 修改秒杀记录
     */
    @RequiresPermissions("system:SeckillRecord:edit")
    @Log(title = "秒杀记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SeckillRecord seckillRecord)
    {
        return toAjax(seckillRecordService.updateSeckillRecord(seckillRecord));
    }

    /**
     * 删除秒杀记录
     */
    @RequiresPermissions("system:SeckillRecord:remove")
    @Log(title = "秒杀记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(seckillRecordService.deleteSeckillRecordByRecordIds(recordIds));
    }
}
